<%--
  Created by IntelliJ IDEA.
  User: 91658
  Date: 2018/6/20
  Time: 16:20
  转账管理
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>转账管理</title>
    <%@ include file="../common/common.jsp" %>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <%@ include file="../common/head.jsp" %>
    <%@ include file="../common/left.jsp" %>
    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="padding: 15px;">
            <div id="formDiv">
                <form id="chargeForm" class="layui-form" onsubmit="return false;">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">转出类型</label>
                            <div class="layui-input-inline">
                                <select lay-search="" id="fromAccountId">
                                    <option value="">直接选择或搜索选择</option>
                                    <c:forEach items="${accountList}" var="account">
                                        <option value="${account.id}">${account.accountName}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">转入类型</label>
                            <div class="layui-input-inline">
                                <select lay-search="" id="toAccountId">
                                    <option value="">直接选择或搜索选择</option>
                                    <c:forEach items="${accountList}" var="account">
                                        <option value="${account.id}">${account.accountName}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">创建时间</label>
                            <div class="layui-input-inline">
                                <input type="text" id="beginDate" placeholder="开始日期" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-input-inline">
                                <input type="text" id="endDate" placeholder="结束日期" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">金额区间</label>
                            <div class="layui-input-inline">
                                <input type="text" id="lowMoney" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-input-inline">
                                <input type="text" id="highMoney" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn" id="formBtn">查询</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            <button class="layui-btn" id="importBtn">导入</button>
                        </div>
                    </div>
                </form>
            </div>

            <div id="tableDiv">
                <table class="layui-hide" id="transferTable" lay-filter="transferTable"></table>
            </div>
        </div>
    </div>
    <%@ include file="../common/bottom.jsp" %>
</div>
</body>
<script type="text/javascript">
    layui.use(['form', 'laydate', 'table', 'upload', 'layer', 'laypage'], function(){
        var $ = layui.jquery;
        var form = layui.form
            ,laydate = layui.laydate
            ,table = layui.table
            ,upload = layui.upload
            ,layer = layui.layer
            ,laypage = layui.laypage;

        form.render('select');
        //日期
        laydate.render({
            elem: '#beginDate'
        });
        laydate.render({
            elem: '#endDate'
        });
        table.render({
            elem: '#transferTable'
            ,url:'/transfer/transfer_record/'
            ,method: 'POST'
            ,cols: [[
                {field:'fromAccountName', width:130, title: '转出账户', sort: true}
                ,{field:'toAccountName', width:130, title: '转入账户', sort: true}
                ,{field:'transferMoney', width:130, title: '金额', sort: true}
                ,{field:'poundage', width:130, title: '手续费'}
                ,{field:'poundageWayName', width:130, title: '手续费扣除方'}
                ,{field:'transferRemark', width: 200, title: '备注'}
                ,{field:'transferTime', title: '时间'}
                ,{fixed: 'right', title: '操作', width:150, align:'center', toolbar: '#toolBar'} //这里的toolbar值是模板元素的选择器
            ]]
            ,response: {
                statusCode: 1 //成功的状态码，默认：0
            }
            ,request: {
                pageName: 'pageNo' //页码的参数名称，默认：page
                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            ,page: true
            ,done: function(res, curr, count){
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                console.log(res);

                //得到当前页码
                console.log(curr);

                //得到数据总量
                console.log(count);
            }
        });
        $("#formBtn").click(function () {
            table.reload('transferTable', {
                where: {
                    fromAccountId: $("#fromAccountId").val()
                    ,toAccountId: $("#toAccountId").val()
                    ,beginDate: $("#beginDate").val()
                    ,endDate: $("#endDate").val()
                    ,lowMoney: $("#lowMoney").val()
                    ,highMoney: $("#highMoney").val()
                }
            });
        });

        //监听工具条
        table.on('tool(chargeTable)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if(layEvent === 'del'){ //删除
                layer.confirm('真的删除行么', function(index){
                    obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                    layer.close(index);
                    //向服务端发送删除指令
                });
            } else if(layEvent === 'edit'){ //编辑
                //do something
                console.log(obj);
                //同步更新缓存对应的值
                obj.update({
                    username: '123'
                    ,title: 'xxx'
                });
            }
        });
        //执行实例
        var uploadInst = upload.render({
            elem: '#importBtn' //绑定元素
            ,url: '/transfer/upload' //上传接口
            ,accept: 'file'
            ,acceptMime: 'application/msexcel'
            ,exts: 'xls|xlsx'
            ,done: function(res){
                //上传完毕回调
                table.reload('transferTable');
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });
</script>
<script type="text/html" id="toolBar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
</html>
